import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

import {postZan,postStart,postIfLikeAndStart,
    postCommentDirect,postCommentReply,
    postDianZan} from '@/api'

const state = {}

const actions = {
    //点赞文章
    async reqZan(context,obj){
        let {item,article_id} = obj;
        let result = await postZan(item,article_id);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //收藏
    async reqStart(context,obj){
        let {item,article_id} = obj;
        let result = await postStart(item,article_id);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //当前用户是否已点赞和已收藏
    async reqIfLikeAndStart(context,article_id){
        let result = await postIfLikeAndStart(article_id);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //直接发布评论
    async reqCommentDirect(context,obj){
        let {article_id,content} = obj;
        let result = await postCommentDirect(article_id,content);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //回复评论
    async reqCommentReply(context,obj){
        let {article_id,father_id,reply_id,root_id,content} = obj
        let result = await postCommentReply(article_id,father_id,reply_id,root_id,content);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //点赞评论
    async reqDianZan(context,obj){
        let {num,comment_id} = obj
        let result = await postDianZan(num,comment_id);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    
}

const mutations = {}

const getters = {}

export default {
    namespaced:true,state,mutations,actions,getters
}